﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;


namespace ElingOA6_Admin_DSJCJ.DAL
{
    /// <summary>
    /// 人员信息DAL
    /// </summary>
    public class HREmpl
    {
        /// <summary>
        /// 是否存在该记录
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool Exists(string fEntityNo, string fEmplNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from t_HREmpl");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = fEntityNo;
            parameters[1].Value = fEmplNo;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 是否是正级
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool isFPositionProp(string fEmplNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  b.FPositionProp
  FROM t_HREmplPosition a,t_HRPosition b
  WHERE a.FPositionNo=b.FPositionNo AND a.FDeptNo=b.FDeptNo AND (FPositionProp=1) and a.FEmplNo=@FEmplNo");

            SqlParameter[] parameters = {
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = fEmplNo;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                if (obj.ToString() == "1")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 是否是正级(副级)
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEmplNo">人员编号</param>
        /// <returns>是否存在记录</returns>
        public bool IsMainOrSub(string emplNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  b.FPositionProp
  FROM t_HREmplPosition a,t_HRPosition b
  WHERE a.FPositionNo=b.FPositionNo AND a.FDeptNo=b.FDeptNo AND (FPositionProp=1 OR FPositionProp=2) and a.FEmplNo=@FEmplNo");

            SqlParameter[] parameters = {
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = emplNo;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj != null)
            {
                if (obj.ToString() == "1" || obj.ToString() == "2")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 获取人员名称
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetEmpName(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FEmpName from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 获取人员名称
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetEmpNameAndDept(string entityNo, string empNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select FEmpName,FEmplNo,FDeptNo,FDeptName,FIsMainPosition from dbo.v_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo AND FIsMainPosition='Y' ");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            DataSet obj = DbHelperSQL.Query(strSql.ToString(), parameters);
            
            string str = " { \"FEmpName\": \"" + obj.Tables[0].Rows[0]["FEmpName"] + "\", \"FEmplNo\": \"" + obj.Tables[0].Rows[0]["FEmplNo"] + "\", \"FDeptName\": \"" + obj.Tables[0].Rows[0]["FDeptName"] + "\", \"FDeptNo\": \"" + obj.Tables[0].Rows[0]["FDeptNo"] + "\" }";
         
            return str;
        }

        public string GetEmpNameAndDeptFIsAllowLookFtp(string entityNo, string empNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"select FEmpName,FEmplNo,FDeptNo,FDeptName,FIsMainPosition from dbo.v_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo AND FIsAllowLookFtp='Y' ");

            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            DataSet obj = DbHelperSQL.Query(strSql.ToString(), parameters);
            string str = " { \"FEmpName\": \"" + obj.Tables[0].Rows[0]["FEmpName"] + "\", \"FEmplNo\": \"" + obj.Tables[0].Rows[0]["FEmplNo"] + "\", \"FDeptName\": \"" + obj.Tables[0].Rows[0]["FDeptName"] + "\", \"FDeptNo\": \"" + obj.Tables[0].Rows[0]["FDeptNo"] + "\",\"Value\":\"" + obj.Tables[0].Rows[0]["FEmplNo"].ToString() + "\" }";
              return str;
        }

        /// <summary>
        /// 删除人员和人员岗位数据 事务模式
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <param name="entityNo">组织机构编号</param>
        public void DelEmlAndPosition(string empNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            //删除人员用户组对应表
            strSql = new StringBuilder();
            cmds = new CommandInfo();

            strSql.Append("DELETE FROM dbo.t_PrvUserGroup WHERE FLogID IN (SELECT FLogID FROM dbo.t_PrvUser WHERE FEntityNo=@FEntityNo and FEmplNo=@FEmplNo)");
            SqlParameter[] parameters2 = new SqlParameter[]{
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters2[0].Value = entityNo;
            parameters2[1].Value = empNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);


            //删除人员岗位数据
            strSql.Append("delete from t_HREmplPosition ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)	};

            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);


            //删除人员数据
            strSql = new StringBuilder();
            cmds = new CommandInfo();

            strSql.Append("delete from t_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters1 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters1[0].Value = entityNo;
            parameters1[1].Value = empNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters1;
            cmdList.Add(cmds);



            DbHelperSQL.ExecuteSqlTranWithString(cmdList);

        }

        /// <summary>
        /// 批量删除人员数据 事务模式
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNoArray">人员列表</param>
        /// <param name="entityNo">组织机构编号</param>
        public void DelManyEmlAndPosition(string[] empNoArray, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();

            if (empNoArray.Length > 0)
            {
                //删除人员用户组对应表
                strSql = new StringBuilder();
                cmds = new CommandInfo();

                strSql.Append("DELETE FROM dbo.t_PrvUserGroup WHERE FLogID IN (SELECT FLogID FROM dbo.t_PrvUser WHERE FEntityNo=@FEntityNo and FEmplNo=@FEmplNo)");
                string strSqlUserGroup = strSql.ToString();

                //删除人员岗位数据
                strSql.Append("delete from t_HREmplPosition ");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                string strSqlPosition = strSql.ToString();

                //删除人员数据
                strSql = new StringBuilder();
                strSql.Append("delete from t_HREmpl ");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                string strSqlEmp = strSql.ToString();


                foreach (string empNo in empNoArray)
                {
                    //人员用户组对应表
                    cmds = new CommandInfo();
                    SqlParameter[] parameters2 = new SqlParameter[]{
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)	};

                    parameters2[0].Value = entityNo;
                    parameters2[1].Value = empNo;

                    cmds.CommandText = strSqlUserGroup;
                    cmds.Parameters = parameters2;
                    cmdList.Add(cmds);

                    //人员岗位数据
                    cmds = new CommandInfo();
                    SqlParameter[] parameters = {
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)	};

                    parameters[0].Value = entityNo;
                    parameters[1].Value = empNo;

                    cmds.CommandText = strSqlPosition;
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);

                    // 人员数据
                    //cmds = new CommandInfo();
                    //SqlParameter[] parameters1 = {
                    //    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
                    //    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    //parameters1[0].Value = entityNo;
                    //parameters1[1].Value = empNo;

                    cmds = new CommandInfo();
                    cmds.CommandText = strSqlEmp;
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);


                }

            }

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }


        /// <summary>
        /// 判断当前选择的岗位是否有正级岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="emplNo">人员编号</param>
        /// <param name="deptNos">部门编号</param>
        /// <param name="positionNos">岗位编号</param>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>是否正级岗位</returns>
        public int GetIsMainPositionCount(string emplNo, string deptNos, string positionNos, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from t_HREmplPosition a left join t_HRPosition b");
            strSql.Append(" on a.FPositionNo=b.FPositionNo and a.FDeptNo=b.FDeptNo");
            strSql.Append(" where a.FEntityNo=@FEntityNo and a.FDeptNo in(");
            strSql.Append(deptNos);
            strSql.Append(") and a.FPositionNo in(");
            strSql.Append(positionNos);
            strSql.Append(") and FPositionProp=1 and FEmplNo <> @FEmplNo");


            SqlParameter[] parameters = {  
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar, 15), 
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar, 15) };

            parameters[0].Value = entityNo;
            parameters[1].Value = emplNo;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (null != obj)
            {
                return int.Parse(obj.ToString());
            }
            else
            {
                return 0;
            }

        }


        /// <summary>
        /// 获取图片二进制流
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="empNo">人员编号</param>
        /// <param name="entityNo">组织机构编号</param>
        /// <returns>2进制图片数据</returns>
        public byte[] GetPhoto(string empNo, string entityNo)
        {
            string strSql = "select  top 1 FPhoto from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return (byte[])obj;
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 保存用户和用户岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <param name="empPositionList">岗位信息</param>
        public void AddEmplAndPosition(Model.HREmpl model, List<Model.HREmplPosition> empPositionList)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();

            //保存员工信息
            strSql.Append("insert into t_HREmpl(");
            strSql.Append("FEntityNo,FEmplNo,FEmpName,FOfficeTel,FTelShortNo,FMobile,FMobShortNo,FEMail,FHomeTel,FHomeAddr,FSex,FIdNo,FBirthday,FNativePlace,FEduNo,FSchool,FSpecialty,FSeq,FPhoto,FDutyNo,FJob,FEmpStatus,FLeaveDate,FIsJoin,FIsCheck,FIsAttendance,FIsAllowAddtionInsPlan,FWorkDate,FLoginIPAddress)");
            strSql.Append(" values (");
            strSql.Append("@FEntityNo,@FEmplNo,@FEmpName,@FOfficeTel,@FTelShortNo,@FMobile,@FMobShortNo,@FEMail,@FHomeTel,@FHomeAddr,@FSex,@FIdNo,@FBirthday,@FNativePlace,@FEduNo,@FSchool,@FSpecialty,@FSeq,@FPhoto,@FDutyNo,@FJob,@FEmpStatus,@FLeaveDate,@FIsJoin,@FIsCheck,@FIsAttendance,@FIsAllowAddtionInsPlan,@FWorkDate,@FLoginIPAddress)");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmpName", SqlDbType.NVarChar,20),
					new SqlParameter("@FOfficeTel", SqlDbType.NVarChar,20),
					new SqlParameter("@FTelShortNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FMobile", SqlDbType.NVarChar,40),
					new SqlParameter("@FMobShortNo", SqlDbType.NVarChar,10),
					new SqlParameter("@FEMail", SqlDbType.NVarChar,80),
					new SqlParameter("@FHomeTel", SqlDbType.NVarChar,20),
					new SqlParameter("@FHomeAddr", SqlDbType.NVarChar,80),
					new SqlParameter("@FSex", SqlDbType.NVarChar,1),
					new SqlParameter("@FIdNo", SqlDbType.VarChar,18),
					new SqlParameter("@FBirthday", SqlDbType.DateTime),
					new SqlParameter("@FNativePlace", SqlDbType.NVarChar,20),
					new SqlParameter("@FEduNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FSchool", SqlDbType.NVarChar,60),
					new SqlParameter("@FSpecialty", SqlDbType.NVarChar,40),
					new SqlParameter("@FSeq", SqlDbType.Int),
					new SqlParameter("@FPhoto", SqlDbType.Image),
					new SqlParameter("@FDutyNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FJob", SqlDbType.NVarChar,2000),
                    new SqlParameter("@FEmpStatus", SqlDbType.NVarChar,30),
					new SqlParameter("@FLeaveDate", SqlDbType.DateTime),
					new SqlParameter("@FIsJoin", SqlDbType.Char,1),
                    new SqlParameter("@FIsCheck", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsAttendance", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsAllowAddtionInsPlan", SqlDbType.NVarChar,1),
                    new SqlParameter("@FWorkDate", SqlDbType.DateTime),
                    new SqlParameter("@FLoginIPAddress", SqlDbType.NVarChar,16)
                                        };
            parameters[0].Value = model.FEntityNo;
            parameters[1].Value = model.FEmplNo;
            parameters[2].Value = model.FEmpName;
            parameters[3].Value = model.FOfficeTel;
            parameters[4].Value = model.FTelShortNo;
            parameters[5].Value = model.FMobile;
            parameters[6].Value = model.FMobShortNo;
            parameters[7].Value = model.FEMail;
            parameters[8].Value = model.FHomeTel;
            parameters[9].Value = model.FHomeAddr;
            parameters[10].Value = model.FSex;
            parameters[11].Value = model.FIdNo;
            parameters[12].Value = model.FBirthday;
            parameters[13].Value = model.FNativePlace;
            parameters[14].Value = model.FEduNo;
            parameters[15].Value = model.FSchool;
            parameters[16].Value = model.FSpecialty;
            parameters[17].Value = model.FSeq;
            parameters[18].Value = model.FPhoto;
            parameters[19].Value = PubConstant.CheckNullToDbNull(model.FDutyNo);
            parameters[20].Value = model.FJob;
            parameters[21].Value = model.FEmpStatus;
            parameters[22].Value = model.FLeaveDate;
            parameters[23].Value = model.FIsJoin;
            parameters[24].Value = model.FIsCheck;
            parameters[25].Value = model.FIsAttendance;
            parameters[26].Value = model.FIsAllowAddtionInsPlan;
            parameters[27].Value = model.FWorkDate;
            parameters[28].Value = model.FLoginIPAddress;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            //保存选择的岗位信息
            if (empPositionList.Count > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("insert into t_HREmplPosition(");
                strSql.Append("FPositionNo,FDeptNo,FEntityNo,FEmplNo,FIsMainPosition)");
                strSql.Append(" values (");
                strSql.Append("@FPositionNo,@FDeptNo,@FEntityNo,@FEmplNo,@FIsMainPosition)");

                string strSqls = strSql.ToString();

                foreach (Model.HREmplPosition positionObj in empPositionList)
                {
                    cmds = new CommandInfo();

                    SqlParameter[] parameters1 = {
					    new SqlParameter("@FPositionNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                        new SqlParameter("@FIsMainPosition", SqlDbType.NVarChar,1)};
                    parameters1[0].Value = positionObj.FPositionNo;
                    parameters1[1].Value = positionObj.FDeptNo;
                    parameters1[2].Value = positionObj.FEntityNo;
                    parameters1[3].Value = model.FEmplNo;
                    parameters1[4].Value = positionObj.FIsMainPosition;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters1;
                    cmdList.Add(cmds);
                }

            }

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }


        /// <summary>
        /// 更新用户和用户岗位
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="model">用户信息</param>
        /// <param name="empPositionList">岗位列表</param>
        public void UpdateEmplAndPosition(Model.HREmpl model, List<Model.HREmplPosition> empPositionList)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            StringBuilder strSql = new StringBuilder();

            //更新员工信息
            strSql.Append("update t_HREmpl set ");
            strSql.Append("FEmpName=@FEmpName,");
            strSql.Append("FOfficeTel=@FOfficeTel,");
            strSql.Append("FTelShortNo=@FTelShortNo,");
            strSql.Append("FMobile=@FMobile,");
            strSql.Append("FMobShortNo=@FMobShortNo,");
            strSql.Append("FEMail=@FEMail,");
            strSql.Append("FHomeTel=@FHomeTel,");
            strSql.Append("FHomeAddr=@FHomeAddr,");
            strSql.Append("FSex=@FSex,");
            strSql.Append("FIdNo=@FIdNo,");
            strSql.Append("FBirthday=@FBirthday,");
            strSql.Append("FNativePlace=@FNativePlace,");
            strSql.Append("FEduNo=@FEduNo,");
            strSql.Append("FSchool=@FSchool,");
            strSql.Append("FSpecialty=@FSpecialty,");
            strSql.Append("FSeq=@FSeq,");
            strSql.Append("FDutyNo=@FDutyNo,");
            strSql.Append("FJob=@FJob,");
            strSql.Append("FEmpStatus=@FEmpStatus,");
            strSql.Append("FLeaveDate=@FLeaveDate,");
            strSql.Append("FIsJoin=@FIsJoin,");
            strSql.Append("FIsCheck=@FIsCheck,");
            strSql.Append("FIsAttendance=@FIsAttendance,");
            strSql.Append("FIsAllowAddtionInsPlan=@FIsAllowAddtionInsPlan,");
            strSql.Append("FWorkDate=@FWorkDate,");
            strSql.Append("FLoginIPAddress=@FLoginIPAddress");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmpName", SqlDbType.NVarChar,20),
					new SqlParameter("@FOfficeTel", SqlDbType.NVarChar,20),
					new SqlParameter("@FTelShortNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FMobile", SqlDbType.NVarChar,40),
					new SqlParameter("@FMobShortNo", SqlDbType.NVarChar,10),
					new SqlParameter("@FEMail", SqlDbType.NVarChar,80),
					new SqlParameter("@FHomeTel", SqlDbType.NVarChar,20),
					new SqlParameter("@FHomeAddr", SqlDbType.NVarChar,80),
					new SqlParameter("@FSex", SqlDbType.NVarChar,1),
					new SqlParameter("@FIdNo", SqlDbType.VarChar,18),
					new SqlParameter("@FBirthday", SqlDbType.DateTime),
					new SqlParameter("@FNativePlace", SqlDbType.NVarChar,20),
					new SqlParameter("@FEduNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FSchool", SqlDbType.NVarChar,60),
					new SqlParameter("@FSpecialty", SqlDbType.NVarChar,40),
					new SqlParameter("@FSeq", SqlDbType.Int),
					new SqlParameter("@FDutyNo", SqlDbType.NVarChar,25),
					new SqlParameter("@FJob", SqlDbType.NVarChar,2000),
                    new SqlParameter("@FEmpStatus", SqlDbType.NVarChar,30),
					new SqlParameter("@FLeaveDate", SqlDbType.DateTime),
					new SqlParameter("@FIsJoin", SqlDbType.Char,1),
					new SqlParameter("@FIsCheck", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsAttendance", SqlDbType.NVarChar,1),
                    new SqlParameter("@FIsAllowAddtionInsPlan", SqlDbType.NVarChar,1),
                    new SqlParameter("@FWorkDate", SqlDbType.DateTime),
                    new SqlParameter("@FLoginIPAddress",SqlDbType.NVarChar,16)
                                        };
            parameters[0].Value = model.FEntityNo;
            parameters[1].Value = model.FEmplNo;
            parameters[2].Value = model.FEmpName;
            parameters[3].Value = model.FOfficeTel;
            parameters[4].Value = model.FTelShortNo;
            parameters[5].Value = model.FMobile;
            parameters[6].Value = model.FMobShortNo;
            parameters[7].Value = model.FEMail;
            parameters[8].Value = model.FHomeTel;
            parameters[9].Value = model.FHomeAddr;
            parameters[10].Value = model.FSex;
            parameters[11].Value = model.FIdNo;
            parameters[12].Value = model.FBirthday;
            parameters[13].Value = model.FNativePlace;
            parameters[14].Value = model.FEduNo;
            parameters[15].Value = model.FSchool;
            parameters[16].Value = model.FSpecialty;
            parameters[17].Value = model.FSeq;
            parameters[18].Value = PubConstant.CheckNullToDbNull(model.FDutyNo);
            parameters[19].Value = model.FJob;
            parameters[20].Value = model.FEmpStatus;
            parameters[21].Value = model.FLeaveDate;
            parameters[22].Value = model.FIsJoin;
            parameters[23].Value = model.FIsCheck;
            parameters[24].Value = model.FIsAttendance;
            parameters[25].Value = model.FIsAllowAddtionInsPlan;
            parameters[26].Value = model.FWorkDate;
            parameters[27].Value = model.FLoginIPAddress;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);


            //更新照片
            if (null != model.FPhoto && model.FPhoto.Length > 0)
            {
                strSql = new StringBuilder();
                cmds = new CommandInfo();

                strSql.Append("update t_HREmpl set ");
                strSql.Append("FPhoto=@FPhoto");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
                SqlParameter[] parameters1 = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),					
					new SqlParameter("@FPhoto", SqlDbType.Image)};
                parameters1[0].Value = model.FEntityNo;
                parameters1[1].Value = model.FEmplNo;
                parameters1[2].Value = model.FPhoto;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters1;
                cmdList.Add(cmds);
            }


            //删除员工对应的所有岗位信息
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from t_HREmplPosition ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters0 = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,50)};
            parameters0[0].Value = model.FEntityNo;
            parameters0[1].Value = model.FEmplNo;

            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters0;
            cmdList.Add(cmds);


            //保存选择的岗位信息
            if (empPositionList.Count > 0)
            {
                strSql = new StringBuilder();
                strSql.Append("insert into t_HREmplPosition(");
                strSql.Append("FPositionNo,FDeptNo,FEntityNo,FEmplNo,FIsMainPosition)");
                strSql.Append(" values (");
                strSql.Append("@FPositionNo,@FDeptNo,@FEntityNo,@FEmplNo,@FIsMainPosition)");

                string strSqls = strSql.ToString();

                foreach (Model.HREmplPosition positionObj in empPositionList)
                {
                    cmds = new CommandInfo();

                    SqlParameter[] parameters1 = {
					    new SqlParameter("@FPositionNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                        new SqlParameter("@FIsMainPosition", SqlDbType.NVarChar,1)};
                    parameters1[0].Value = positionObj.FPositionNo;
                    parameters1[1].Value = positionObj.FDeptNo;
                    parameters1[2].Value = positionObj.FEntityNo;
                    parameters1[3].Value = model.FEmplNo;
                    parameters1[4].Value = positionObj.FIsMainPosition;

                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters1;
                    cmdList.Add(cmds);
                }

            }


            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }



        /// <summary>
        /// 获得一个实体对象
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fEntityNo">组织机构编号</param>
        /// <param name="fEmplNo">用户编号</param>
        /// <returns>用户信息</returns>
        public Model.HREmpl GetModel(string fEntityNo, string fEmplNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 FEntityNo,FEmplNo,FEmpName,FOfficeTel,FTelShortNo,FMobile,FMobShortNo,FEMail,FHomeTel,FHomeAddr,FSex,FIdNo,FBirthday,FNativePlace,FEduNo,FSchool,FSpecialty,FSeq,FPhoto,FDutyNo,FJob,FEmpStatus,FLeaveDate,FIsJoin,FIsCheck,FIsAttendance,FIsAllowAddtionInsPlan,FWorkDate,FLoginIPAddress from t_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)			};
            parameters[0].Value = fEntityNo;
            parameters[1].Value = fEmplNo;

            Model.HREmpl model = new Model.HREmpl();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FEntityNo"] != null && ds.Tables[0].Rows[0]["FEntityNo"].ToString() != "")
                {
                    model.FEntityNo = ds.Tables[0].Rows[0]["FEntityNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEmplNo"] != null && ds.Tables[0].Rows[0]["FEmplNo"].ToString() != "")
                {
                    model.FEmplNo = ds.Tables[0].Rows[0]["FEmplNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEmpName"] != null && ds.Tables[0].Rows[0]["FEmpName"].ToString() != "")
                {
                    model.FEmpName = ds.Tables[0].Rows[0]["FEmpName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FOfficeTel"] != null && ds.Tables[0].Rows[0]["FOfficeTel"].ToString() != "")
                {
                    model.FOfficeTel = ds.Tables[0].Rows[0]["FOfficeTel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FTelShortNo"] != null && ds.Tables[0].Rows[0]["FTelShortNo"].ToString() != "")
                {
                    model.FTelShortNo = ds.Tables[0].Rows[0]["FTelShortNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FMobile"] != null && ds.Tables[0].Rows[0]["FMobile"].ToString() != "")
                {
                    model.FMobile = ds.Tables[0].Rows[0]["FMobile"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FMobShortNo"] != null && ds.Tables[0].Rows[0]["FMobShortNo"].ToString() != "")
                {
                    model.FMobShortNo = ds.Tables[0].Rows[0]["FMobShortNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEMail"] != null && ds.Tables[0].Rows[0]["FEMail"].ToString() != "")
                {
                    model.FEMail = ds.Tables[0].Rows[0]["FEMail"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FHomeTel"] != null && ds.Tables[0].Rows[0]["FHomeTel"].ToString() != "")
                {
                    model.FHomeTel = ds.Tables[0].Rows[0]["FHomeTel"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FHomeAddr"] != null && ds.Tables[0].Rows[0]["FHomeAddr"].ToString() != "")
                {
                    model.FHomeAddr = ds.Tables[0].Rows[0]["FHomeAddr"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSex"] != null && ds.Tables[0].Rows[0]["FSex"].ToString() != "")
                {
                    model.FSex = ds.Tables[0].Rows[0]["FSex"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FIdNo"] != null && ds.Tables[0].Rows[0]["FIdNo"].ToString() != "")
                {
                    model.FIdNo = ds.Tables[0].Rows[0]["FIdNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FBirthday"] != null && ds.Tables[0].Rows[0]["FBirthday"].ToString() != "")
                {
                    model.FBirthday = DateTime.Parse(ds.Tables[0].Rows[0]["FBirthday"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FNativePlace"] != null && ds.Tables[0].Rows[0]["FNativePlace"].ToString() != "")
                {
                    model.FNativePlace = ds.Tables[0].Rows[0]["FNativePlace"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEduNo"] != null && ds.Tables[0].Rows[0]["FEduNo"].ToString() != "")
                {
                    model.FEduNo = ds.Tables[0].Rows[0]["FEduNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSchool"] != null && ds.Tables[0].Rows[0]["FSchool"].ToString() != "")
                {
                    model.FSchool = ds.Tables[0].Rows[0]["FSchool"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSpecialty"] != null && ds.Tables[0].Rows[0]["FSpecialty"].ToString() != "")
                {
                    model.FSpecialty = ds.Tables[0].Rows[0]["FSpecialty"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FSeq"] != null && ds.Tables[0].Rows[0]["FSeq"].ToString() != "")
                {
                    model.FSeq = int.Parse(ds.Tables[0].Rows[0]["FSeq"].ToString());
                }
                if (ds.Tables[0].Rows[0]["FPhoto"] != null && ds.Tables[0].Rows[0]["FPhoto"].ToString() != "")
                {
                    model.FPhoto = (byte[])ds.Tables[0].Rows[0]["FPhoto"];
                }
                if (ds.Tables[0].Rows[0]["FDutyNo"] != null && ds.Tables[0].Rows[0]["FDutyNo"].ToString() != "")
                {
                    model.FDutyNo = ds.Tables[0].Rows[0]["FDutyNo"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FJob"] != null && ds.Tables[0].Rows[0]["FJob"].ToString() != "")
                {
                    model.FJob = ds.Tables[0].Rows[0]["FJob"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FEmpStatus"] != null && ds.Tables[0].Rows[0]["FEmpStatus"].ToString() != "")
                {
                    model.FEmpStatus = ds.Tables[0].Rows[0]["FEmpStatus"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FLeaveDate"] != null && ds.Tables[0].Rows[0]["FLeaveDate"].ToString() != "")
                {
                    model.FLeaveDate = DateTime.Parse(ds.Tables[0].Rows[0]["FLeaveDate"].ToString());
                }

                if (ds.Tables[0].Rows[0]["FIsJoin"] != null)
                {
                    model.FIsJoin = ds.Tables[0].Rows[0]["FIsJoin"].ToString();
                }

                if (ds.Tables[0].Rows[0]["FIsCheck"] != null)
                {
                    model.FIsCheck = ds.Tables[0].Rows[0]["FIsCheck"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FIsAttendance"] != null)
                {
                    model.FIsAttendance = ds.Tables[0].Rows[0]["FIsAttendance"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FIsAllowAddtionInsPlan"] != null)
                {
                    model.FIsAllowAddtionInsPlan = ds.Tables[0].Rows[0]["FIsAllowAddtionInsPlan"].ToString();
                }
                if (ds.Tables[0].Columns.Contains("FWorkDate"))
                {
                    if (ds.Tables[0].Rows[0]["FWorkDate"] != null && ds.Tables[0].Rows[0]["FWorkDate"].ToString() != "")
                    {
                        model.FWorkDate = DateTime.Parse(ds.Tables[0].Rows[0]["FWorkDate"].ToString());
                    }
                }
                if (ds.Tables[0].Columns.Contains("FLoginIPAddress"))
                {
                    if (ds.Tables[0].Rows[0]["FLoginIPAddress"] != null)
                    {
                        model.FLoginIPAddress = ds.Tables[0].Rows[0]["FLoginIPAddress"].ToString();
                    }
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 根据员工编号从V_HREmpl中获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-18</date>
        /// </summary>
        /// <param name="emplNo">员工</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetEmplFromViewByEmplNo(string emplNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo, FEmplNo, FEmpName, FDeptNo, FDeptName ,FPositionNo,FIsMainPosition ");
            strSql.Append(" FROM v_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50),
                   new SqlParameter("@FEmplNo",SqlDbType.NVarChar,50)};
            parameters[0].Value = entityNo;
            parameters[1].Value = emplNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新用户基本信息
        /// <creator>wangl</creator>
        /// <date>2013-10-19</date>
        /// </summary>
        /// <param name="hrEmplModel"></param>
        public void UpdateEmplBaseInfo(Model.HREmpl hrEmplModel)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_HREmpl set ");
            strSql.Append("FOfficeTel=@FOfficeTel,");
            strSql.Append("FTelShortNo=@FTelShortNo,");
            strSql.Append("FMobile=@FMobile,");
            strSql.Append("FMobShortNo=@FMobShortNo,");
            strSql.Append("FEMail=@FEMail,");
            strSql.Append("FHomeTel=@FHomeTel,");
            strSql.Append("FBirthday=@FBirthday");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
					
					new SqlParameter("@FOfficeTel", SqlDbType.NVarChar,20),
					new SqlParameter("@FTelShortNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FMobile", SqlDbType.NVarChar,40),
					new SqlParameter("@FMobShortNo", SqlDbType.NVarChar,10),
					new SqlParameter("@FEMail", SqlDbType.NVarChar,80),
					new SqlParameter("@FHomeTel", SqlDbType.NVarChar,20),
                    new SqlParameter("@FBirthday", SqlDbType.DateTime)
                                        };
            parameters[0].Value = hrEmplModel.FEntityNo;
            parameters[1].Value = hrEmplModel.FEmplNo;
            parameters[2].Value = hrEmplModel.FOfficeTel;
            parameters[3].Value = hrEmplModel.FTelShortNo;
            parameters[4].Value = hrEmplModel.FMobile;
            parameters[5].Value = hrEmplModel.FMobShortNo;
            parameters[6].Value = hrEmplModel.FEMail;
            parameters[7].Value = hrEmplModel.FHomeTel;
            parameters[8].Value = hrEmplModel.FBirthday;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

        }
        /// <summary>
        /// 获取该部门所有人员
        /// <creator>wangl</creator>
        /// <date>2013-10-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <returns></returns>
        public DataSet GetDeptEmplList(string entityNo,string deptNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEmplNo,FEmpName,FOfficeTel,FMobile,FSex,FDutyNo,FLoginIPAddress from v_HREmpl ");
            strSql.Append(" where  FEntityNo=@FEntityNo AND FDeptNo=@FDeptNo");
            strSql.Append(" AND FIsMainPosition='Y' ");
            strSql.Append(" ORDER BY FSeq,FDutyNo");
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
                    new SqlParameter("@FDeptNo", SqlDbType.NVarChar,12)                    
                                        };
            parameters[0].Value = entityNo;
            parameters[1].Value = deptNo;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds;
        }
        /// <summary>
        /// 人员排序
        /// <creator>wangl</creator>
        /// <date>2013-08-02</date> 
        /// </summary>
        /// <param name="emplNos">员工编号集合</param>
        /// <param name="entityNo">公司编号</param>
        public void SeqEmplTop(string[] emplNos, string entityNo)
        {
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds;
            StringBuilder strSql;
            int intTopSeq = 0;
            foreach (string emplNo in emplNos)
            {
                intTopSeq++;
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update t_HREmpl set FSeq=@FSeq where FEmplNo=@FEmplNo and FEntityNo=@FEntityNo");

                SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),					
					new SqlParameter("@FSeq", SqlDbType.Int,4)};

                parameters[0].Value = entityNo;
                parameters[1].Value = emplNo;
                parameters[2].Value = intTopSeq;

                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);
            }

            DbHelperSQL.ExecuteSqlTranWithString(cmdList);
        }

        /// <summary>
        /// 获取是否需要考勤
        /// <creator>chenly(wangl引用)</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetIsAttendance(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FIsAttendance from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 获取考勤IP
        /// <creator>chenly(wangl引用)</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetAttendanceIpAddress(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FAttendanceIpAddress from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }

        ///// <summary>
        ///// 根据公司编号获取员工表
        ///// <creator>sunlj</creator>
        ///// <date>2013-7-18</date>
        ///// </summary>
        ///// <param name="FEntityNo">公司编号</param>
        ///// <returns>返回员工表数据</returns>
        //public List<Model.HREmpl> GetModelListByEntityNo(string FEntityNo)
        //{
        //    List<Model.HREmpl> hrEmplObjects = new List<Model.HREmpl>();

        //    StringBuilder strSql = new StringBuilder();
        //    strSql.Append("select FEntityNo,FEmplNo,FEmpName,FOfficeTel,FTelShortNo,FMobile,FMobShortNo,FEMail,FHomeTel,FHomeAddr,FSex,FIdNo,FBirthday,FNativePlace,FEduNo,FSchool,FSpecialty,FSeq,FPhoto,FDutyNo,FJob,FEmpStatus,FLeaveDate from t_HREmpl ");
        //    strSql.Append(" where  FEntityNo=@FEntityNo");
        //    SqlParameter[] parameters = {
        //            new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)	};
        //    parameters[0].Value = FEntityNo;

        //    DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
        //    if (ds.Tables[0].Rows.Count > 0)
        //    {
        //        foreach (DataRow row in ds.Tables[0].Rows)
        //        {
        //            Model.HREmpl model = new Model.HREmpl();
        //            if (row["FEntityNo"] != null && row["FEntityNo"].ToString() != "")
        //            {
        //                model.FEntityNo = row["FEntityNo"].ToString();
        //            }
        //            if (row["FEmplNo"] != null && row["FEmplNo"].ToString() != "")
        //            {
        //                model.FEmplNo = row["FEmplNo"].ToString();
        //            }
        //            if (row["FEmpName"] != null && row["FEmpName"].ToString() != "")
        //            {
        //                model.FEmpName = row["FEmpName"].ToString();
        //            }
        //            if (row["FOfficeTel"] != null && row["FOfficeTel"].ToString() != "")
        //            {
        //                model.FOfficeTel = row["FOfficeTel"].ToString();
        //            }
        //            if (row["FTelShortNo"] != null && row["FTelShortNo"].ToString() != "")
        //            {
        //                model.FTelShortNo = row["FTelShortNo"].ToString();
        //            }
        //            if (row["FMobile"] != null && row["FMobile"].ToString() != "")
        //            {
        //                model.FMobile = row["FMobile"].ToString();
        //            }
        //            if (row["FMobShortNo"] != null && row["FMobShortNo"].ToString() != "")
        //            {
        //                model.FMobShortNo = row["FMobShortNo"].ToString();
        //            }
        //            if (row["FEMail"] != null && row["FEMail"].ToString() != "")
        //            {
        //                model.FEMail = row["FEMail"].ToString();
        //            }
        //            if (row["FHomeTel"] != null && row["FHomeTel"].ToString() != "")
        //            {
        //                model.FHomeTel = row["FHomeTel"].ToString();
        //            }
        //            if (row["FHomeAddr"] != null && row["FHomeAddr"].ToString() != "")
        //            {
        //                model.FHomeAddr = row["FHomeAddr"].ToString();
        //            }
        //            if (row["FSex"] != null && row["FSex"].ToString() != "")
        //            {
        //                model.FSex = row["FSex"].ToString();
        //            }
        //            if (row["FIdNo"] != null && row["FIdNo"].ToString() != "")
        //            {
        //                model.FIdNo = row["FIdNo"].ToString();
        //            }
        //            if (row["FBirthday"] != null && row["FBirthday"].ToString() != "")
        //            {
        //                model.FBirthday = DateTime.Parse(row["FBirthday"].ToString());
        //            }
        //            if (row["FNativePlace"] != null && row["FNativePlace"].ToString() != "")
        //            {
        //                model.FNativePlace = row["FNativePlace"].ToString();
        //            }
        //            if (row["FEduNo"] != null && row["FEduNo"].ToString() != "")
        //            {
        //                model.FEduNo = row["FEduNo"].ToString();
        //            }
        //            if (row["FSchool"] != null && row["FSchool"].ToString() != "")
        //            {
        //                model.FSchool = row["FSchool"].ToString();
        //            }
        //            if (row["FSpecialty"] != null && row["FSpecialty"].ToString() != "")
        //            {
        //                model.FSpecialty = row["FSpecialty"].ToString();
        //            }
        //            if (row["FSeq"] != null && row["FSeq"].ToString() != "")
        //            {
        //                model.FSeq = int.Parse(row["FSeq"].ToString());
        //            }
        //            if (row["FPhoto"] != null && row["FPhoto"].ToString() != "")
        //            {
        //                model.FPhoto = (byte[])row["FPhoto"];
        //            }
        //            if (row["FDutyNo"] != null && row["FDutyNo"].ToString() != "")
        //            {
        //                model.FDutyNo = row["FDutyNo"].ToString();
        //            }
        //            if (row["FJob"] != null && row["FJob"].ToString() != "")
        //            {
        //                model.FJob = row["FJob"].ToString();
        //            }
        //            if (row["FEmpStatus"] != null && row["FEmpStatus"].ToString() != "")
        //            {
        //                model.FEmpStatus = row["FEmpStatus"].ToString();
        //            }
        //            if (row["FLeaveDate"] != null && row["FLeaveDate"].ToString() != "")
        //            {
        //                model.FLeaveDate = DateTime.Parse(row["FLeaveDate"].ToString());
        //            }
        //            hrEmplObjects.Add(model);
        //        }
        //    }
        //    return hrEmplObjects;
        //}



        /// <summary>
        /// 获取该部门所有人员
        /// <creator>sunlj</creator>
        /// <date>2013-10-23</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <param name="deptNo">部门编号</param>
        /// <returns></returns>
        public DataSet GetEmplList(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEmplNo,FEmpName,FOfficeTel,FMobile,FSex,FDutyNo from v_HREmpl ");
            strSql.Append(" where  FEntityNo=@FEntityNo ");
            strSql.Append(" AND FEmpStatus!='99' ");
            strSql.Append(" ORDER BY FSeq,FDutyNo");
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),             
                                        };
            parameters[0].Value = entityNo;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds;
        }
        public DataSet GetEmplListFIsAllowLookFtp(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEmplNo,FEmpName,FOfficeTel,FMobile,FSex,FDutyNo from v_HREmpl ");
            strSql.Append(" where  FEntityNo=@FEntityNo ");
            strSql.Append(" AND FEmpStatus!='99' and FIsAllowLookFtp='Y' ");
            strSql.Append(" ORDER BY FSeq,FDutyNo");
            SqlParameter[] parameters = {
                    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),             
                                        };
            parameters[0].Value = entityNo ;

            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds;
        }
        public void UpdataEmplFIsAllowLookFtp(List<Model.HREmpl> emplModelList, string EntityNo)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            CommandInfo cmds = new CommandInfo();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            cmds = new CommandInfo();
            strSql2.Append(" update t_HREmpl set");
            strSql2.Append(" FIsAllowLookFtp='N'");
            strSql2.Append(" where FEntityNo=@FEntityNo ");
            SqlParameter[] parameters2 = {
                      
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12)
					    };
           
            parameters2[0].Value =EntityNo;
           
            cmds.CommandText = strSql2.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);
            if (emplModelList.Count > 0)
            {
                strSql.Append(" update t_HREmpl set");
                strSql.Append(" FIsAllowLookFtp=@FIsAllowLookFtp");
                strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo ");

                foreach (Model.HREmpl model in emplModelList)
                {

                    cmds = new CommandInfo();

                    SqlParameter[] parameters = {
                        new SqlParameter("@FIsAllowLookFtp", SqlDbType.NVarChar,1),
					    new SqlParameter("@FEntityNo", SqlDbType.NVarChar,12),
					    new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
                    parameters[0].Value = model.FIsAllowLookFtp;
                    parameters[1].Value = model.FEntityNo;
                    parameters[2].Value = model.FEmplNo;
                    cmds.CommandText = strSql.ToString();
                    cmds.Parameters = parameters;
                    cmdList.Add(cmds);
                }
            }
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }



    }
}

